<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>借阅登记</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <jsp:include page="/inc/head.jsp" flush="true"/>
    <jsp:include page="/inc/footer.jsp" flush="true"/>
    <script src="${basePath }/js/tip.js"></script>
    <style>
        .content #rowTable .box {
            border-top:0;
        }
        .content #rowTable .box .bootstrap-table .fixed-table-toolbar {
            position: absolute;
            right: 0;
            top: -44px;
        }
        .content #rowTable .box .bootstrap-table .fixed-table-container {
            margin-top: 10px;
        }
        .content #rowTable .box .bootstrap-table .fixed-table-toolbar  .icon-refresh {
            padding: 3px 0;
        }

        .content .btn-default{
            height: 34px;!important;
        }
    </style>
</head>
<body class="hold-transition skin-blue sidebar-mini" style="overflow:hidden;">
<!-- Main content -->
<section class="content">

    <table id="tableone"></table>

    <!-- 审核内容展示 -->
    <div id="modal">
        <div id="approvalInfoModal" class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-full">
                <div class="modal-content">
                    <div class="modal-header bg-primary" >
                        <%--<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>--%>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">
                            <i class="icon-pencil"></i>
                            <span class="addFileTitle"  style="font-weight:bold">审核详情</span>
                        </h4>
                    </div>
                   <div class="pa15">
                       <table id="approvalInfoTable" class="RollItemTable">
                       </table>
                   </div>
                </div>
            </div>
        </div>
    </div>
</section>
</body>
<script type="text/javascript">
    var $tableone = $('#tableone');
    $(document).ready(function(){
        $tableone.bootstrapTable({
            url:"${basePath}/pcwindow/getBorRegiser",
            striped: true,
            search: true,
            showRefresh: true,
            showColumns: true,
            minimumCountColumns:2,
            clickToSelect: true,
            detailView: false,
//            detailFormatter: 'cmsBorRegisterView',
            pagination: true,
            pageSize: 50,
            pageList:[50,100],
            sidePagination: 'server',
            silentSort: false,
            smartDisplay: false,
            escape: true,
            searchOnEnterKey: true,
            idField: 'REGISTID',
            maintainSelected: true,
            toolbar: '#toolbar',
            columns :[
                {field: 'ck', checkbox: true},
                {field: 'REGISTID', visible:false},
                {field: 'REGISTERNUM', title: '登记号', align: 'center'},
//                {field: 'TITLE', title: '题名', align: 'center'},
                {field: 'USERNAME', title: '借阅人', align: 'center'},
                {field: 'DEPTNAME', title: '借阅人部门', align: 'center',formatter:'deptNameFormatter'},
                {field: 'TITLE', title: '借阅文件', align: 'center'},
                {field: 'BORTYPE', title: '借阅形式', align: 'center',formatter:'borTypeFormatter'},
//                {field: 'BORTIME', title: '借阅时间',formatter:'timeFormatter'},
                {field: 'PLANRETURNTIME', title: '借阅截止时间', align: 'center',formatter:'timeFormatter'},
                {field: 'BORSTATUS', title: '借阅状态', align: 'center',formatter:'borStatusFormatter'},
                {field: 'FILESHAPE', title: '文件形式', align: 'center', formatter:"fileshapeFormatter"},
                {field: '', title: '操作', align: 'center',formatter:'optionFormatter'}
            ],
            onLoadSuccess:function(data){
                //无数据隐藏分页
                if(data && data.total == 0){
                    $('.fixed-table-pagination').hide()
                }
            }
        })
        $tableone.bootstrapTable('resetView',{height:setHeight()});
    })

    /*审核信息按钮*/
    function optionFormatter(value, row, index){
        return  [
            '<a class="borrowing" href="javascript:;" onclick="viewApprovalInfo(' + row.REGISTID +')" data-toggle="tooltip" title="bor"><i class="glyphicon glyphicon-eye-open"></i></a>'
        ].join('');
    }

    //初始化借阅形式
    function borTypeFormatter(value, row, index) {
        if(value==0){
            return "线上";
        }else{
            return "线下";
        }
    }

    //初始化借阅状态
    function borStatusFormatter(value, row, index) {
        if(value===0){
            return "未借出";
        }else if(value===1){
            return "已借出";
        }else if(value===2){
            return "已失效";
        }else{
            return "已归还";
        }
    }

    //文件形式转换
    function fileshapeFormatter(value, row, index) {
        if(value==0){
            return "卷";
        }else if(value==1){
            return "卷内件";
        }else if(value==2) {
            return "单件";
        }
    }

    //时间类型转换
    function timeFormatter(value, row, index) {
        return longToDate(value);
    }

    //初始化部门名称格式
    function deptNameFormatter(value, row, index) {
        if(value==null||typeof(value)=="undefined"){
            return row.BORDEPTDESCRIPTION;
        }else{
            return value;
        }
    }


    /*审核详情table*/
    $('#approvalInfoTable').bootstrapTable({
        striped: true,
        search: false,
        minimumCountColumns: 2,
        clickToSelect: true,
        detailView: false,
        detailFormatter: '',
        pagination: true,
        paginationLoop: false,
        sidePagination: 'server',
        silentSort: false,
        smartDisplay: false,
        escape: true,
        searchOnEnterKey: true,
        idField: 'tagId',
        maintainSelected: true,
        toolbar: '#toolbar',
        columns: [
            {field: 'USERNAME', title: '审核人', align: 'center'},
            {field: 'AUDIT_USER_VIEW', title: '审核人意见',  align: 'center'},
            {field: 'AUDIT_TYPE', title: '审核类型', align: 'center',formatter:'auditTypeFormat'},
            {field: 'RESULT_TYPE', title: '审核结果', align: 'center',formatter:'resultFormat'},
            {field: 'CREATE_TIME', title: '审核时间', align: 'center',formatter:'timeFormat'}
        ]
    })
    /**
     * 审核信息详情
     * @param id
     */
    function viewApprovalInfo(id){
        var url="/pcwindow/approvalInfoList?id="+id;
        var rows = $tableone.bootstrapTable('getSelections');
        $('#approvalInfoTable').bootstrapTable(
            "refreshOptions",
            {
                url : url, // 获取数据的地址
            }
        );


        $("#approvalInfoModal").modal({
            keyboard: true
        });

        // showModal()
    }

    //初始化时间转换
    function timeFormat(value,row,index){
        return formatshortDateTime(value);
    }

    //借阅类型转换
    function auditTypeFormat(value,row,index){
        if(value==0){
            return "借阅";
        }else{
            return "续借";
        }
    }

    //借阅结果初始化
    function resultFormat(value,row,index){
        if(value==0){
            return '<span  class="label label-danger">不通过</span>';
        }else{
            return '<span  class="label label-success">通过</span>';
        }
    }
    // 优化弹窗（顶级窗口显示）
    function showModal() {
        var topBody = $(top.document.body);
        topBody.append($("#modal").html());

        // 打开父页面的modal框
        window.top.$("#approvalInfoModal").modal();

        // 阻止模态框的多次弹出
        window.top.$("#approvalInfoModal").on('hidden.bs.modal', function () {
            if ($("#approvalInfoModal", top.document) != null) {
                $("#approvalInfoModal", top.document).remove();
            }
            return;
        });
    }
    /**
     * 表格高度自适应
     * @return
     * winTop 浏览器视口高度
     * header 顶部通栏
     * breadcrumb 面包屑
     * mainFooter 底部
     */
    function setHeight(){
        var winTop = $(window.top).height(),
            header = window.top.document.querySelector('.main-header').offsetHeight,
            breadcrumb =  window.top.document.querySelector('.breadcrumb').offsetHeight,
            mainFooter = window.top.document.querySelector('.main-footer').offsetHeight;
            // toolbar = document.querySelector('#toolbar').offsetHeight;
        return winTop-header-breadcrumb-mainFooter-10;
    }
</script>
</html>